<?php
echo $this->Html->script('jquery.validate.min');
echo $this->Html->script('common');
echo $this->Html->script('jquery.autocomplete.min');
echo $this->Html->script('jquery.bgiframe.min');

echo $this->Html->css('jquery.autocomplete');
?>
<script type="text/javascript">
    $(document).ready(function(){

        $("form").validate({
            errorClass: "jqueryError",
            errorElement: 'label',
            debug: false,
            submitHandler: function(form) {
                $(':submit', form).attr('disabled', 'disabled').addClass('inactive');
                form.submit();
            }
        });

        $("#UserTags").keyup(function(){
            var usertags = $("#UserTags").val();
            var tags = usertags.split(",");
            var flag = false;
            while(tags.length > 5)
            {
                flag = true;
                tags.pop();
                $("#UserTags").val(tags);
            }
            if(flag == true)
                alert("A maximum of 5 tags are allowed.");
        });

        $('#UserTags').autocomplete('<?php echo $this->Html->url(array('plugin' => 'tags', 'controller' => 'tags', 'action' => 'displayTags', 'admin' => false)); ?>', {
            minChars: 2,
            max:5, /* maximum number of records to display at one time */
            autoFill: true,
            multiple: true,
            multipleSeparator: ","
        });

        $('#UserStateId').change(function() {
            if($('#UserStateId').val() != "")
            {
                populateSelectBox('UserCityId', 'get', '<?php echo $this->Html->url(array('controller' => 'cities', 'action' => 'getCities', 'admin' => false)); ?>', {stateId: $(this).val()});
            }
            else
            {
                $('#UserCityId').empty();
            }
        });
    });
</script>
<?php
echo $this->Form->input('firstname', array(
    'label' => 'First Name',
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Only letters and numbers, atleast 2 characters)', array('class' => 'description'))
));

echo $this->Form->input('lastname', array(
    'label' => 'Last Name',
    'between' => $this->Html->tag('span', '(Only letters and numbers, atleast 2 characters)', array('class' => 'description'))
));

echo $this->Form->input('address', array(
    'type' => 'textarea',
    'label' => 'Address',
    'between' => $this->Html->tag('span', '(Enter address)', array('class' => 'description'))
));

echo $this->Form->input('state_id', array(
    'type' => 'select',
    'secure' => false,
    'options' => $states,
    'selected' => isset($this->data['City']['State']['id']) ? $this->data['City']['State']['id'] : "",
    'empty' => 'Select',
    'label' => 'State',
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Choose your state)', array('class' => 'description'))
));

echo $this->Form->input('city_id', array(
    'label' => 'City',
    'empty' => 'Select',
    'options' => isset($this->data['City']['id']) ? array($this->data['City']['id'] => $this->data['City']['name'])
        : "",
    'class' => 'required',
    'between' => $this->Html->tag('span', '(Choose a city)', array('class' => 'description'))
));

echo $this->Form->input('pincode', array(
    'label' => 'Pincode',
    'between' => $this->Html->tag('span', '(Enter pincode)', array('class' => 'description'))
));

echo $this->Form->input('residencephone', array(
    'label' => 'Residence Phone',
    'between' => $this->Html->tag('span', '(Enter residence phone)', array('class' => 'description'))
));

echo $this->Form->input('officephone1', array(
    'label' => 'Office Phone 1',
    'between' => $this->Html->tag('span', '(Enter office phone number)', array('class' => 'description'))
));

echo $this->Form->input('officephone2', array(
    'label' => 'Office Phone 2',
    'between' => $this->Html->tag('span', '(Enter office phone number)', array('class' => 'description'))
));

echo $this->Form->input('mobilephone', array(
    'label' => 'Mobile Phone',
    'between' => $this->Html->tag('span', '(Enter mobile number)', array('class' => 'description'))
));

echo $this->Form->input('email1', array(
    'label' => 'Primary Email',
    'class' => 'email',
    'between' => $this->Html->tag('span', '(Enter primary email)', array('class' => 'description'))
));

echo $this->Form->input('email2', array(
    'label' => 'Secondary Email',
    'class' => 'email',
    'between' => $this->Html->tag('span', '(Enter secondary email)', array('class' => 'description'))
));

echo $this->Form->input('profession', array(
    'label' => 'Profession',
    'options' => array('student' => 'Student', 'employed' => 'Employed', 'unemployed' => 'Unemployed'),
    'empty' => 'Select',
    'between' => $this->Html->tag('span', '(Choose a profession)', array('class' => 'description'))
));

echo $this->Form->input('leadsource_id', array(
    'label' => 'Lead Source',
    'empty' => 'Select',
    'between' => $this->Html->tag('span', '(Choose a lead source)', array('class' => 'description'))
));

echo $this->Form->input('location_id', array(
    'label' => 'Location',
    'empty' => 'Select',
    'between' => $this->Html->tag('span', '(Choose a location where this user will be handled)', array('class' => 'description'))
));

echo $this->Form->input('awarenesssource_id', array(
    'label' => 'Awareness Source',
    'empty' => 'Select',
    'between' => $this->Html->tag('span', '(Choose an awareness source)', array('class' => 'description'))
));

echo $this->Form->input('preferredcommunication', array(
    'type' => 'select',
    'options' => array('email' => 'Email', 'phone' => 'phone', 'meeting' => 'Meeting'),
    'empty' => 'Select',
    'label' => 'Preferred Communication',
    'between' => $this->Html->tag('span', '(Choose a preferred mode of communication)', array('class' => 'description'))
));

echo $this->Form->input('Send Material', array(
    'type' => 'radio',
    'options' => array('yes' => 'yes', 'no' => 'no'),
    'attributes' => array('legend' => true),
    'name' => 'data[User][sendmaterial]'
));

echo $this->Form->input('employee_id', array(
    'type' => 'hidden',
    'value' => $this->Session->read('Auth.Employee.id')
));

echo $this->Form->input('tags', array(
    'type' => 'text',
    'between' => $this->Html->tag('span', '(A maximum of 5 tags are allowed, comma separated, enter atleast 2 chars for suggestions)', array('class' => 'description'))
));

echo $this->Form->input('status', array(
    'label' => 'Status',
    'checked' => true,
    'after' => $this->Html->tag('span', '(Uncheck to set the status as "disabled")', array('class' => 'description'))
));
?>